package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.ChineseMedicineDTO;
import com.yxx.medicinepojo.dto.WesternMedicineDTO;
import com.yxx.medicinepojo.dto.WesternMedicinePageQueryDTO;
import com.yxx.medicinepojo.vo.ChineseMedicineVO;
import com.yxx.medicinepojo.vo.WesternMedicineVO;
import com.yxx.service.WesternMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author yuxiangxun
 * @date 2024/9/21
 * @apiNote
 */
@RestController
@Api(tags = "西药管理")
@Slf4j
@RequestMapping("/admin/westernmedicine")
public class WesternMedicineController {
    @Autowired
    private WesternMedicineService westernMedicineService;

    /**
     * 西药分页查询
     * @param westernMedicinePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("西药分页")
    public ResponseResult<PageResult> WesternMedicinePage(WesternMedicinePageQueryDTO westernMedicinePageQueryDTO){
        PageResult page = westernMedicineService.westernMedicinePage(westernMedicinePageQueryDTO);
        return ResponseResult.success(page);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询西药")
    public ResponseResult<List<WesternMedicineVO>> ChineseMedicineList(Long categoryId, String name){
        List<WesternMedicineVO> list = westernMedicineService.list(categoryId,name);
        return ResponseResult.success(list);
    }

    /**
     * 西药上线下架
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("西药上线下架")
    public ResponseResult startOrstop(
            @ApiParam(value = "状态 0:下架 1:上架", required = true) @PathVariable("status") Integer status,
            @ApiParam(value = "西药id") Long id){
        westernMedicineService.StartOrStop(status,id);
        return ResponseResult.success();
    }

    /**
     * 新增药品
     * @param westernMedicineDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增西药")
    public ResponseResult save(@RequestBody WesternMedicineDTO westernMedicineDTO){
        westernMedicineService.save(westernMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 修改中药
     * @param westernMedicineDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改西药")
    public ResponseResult update(@RequestBody WesternMedicineDTO westernMedicineDTO){
        westernMedicineService.updateWesternMedicine(westernMedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("回显数据，根据id查询中药")
    public ResponseResult<WesternMedicineVO> WesternMedicineSelectUpdateById(@PathVariable Long  id){
        WesternMedicineVO westernMedicineVO = westernMedicineService.WesternMedicineSelectUpdateById(id);
        return ResponseResult.success(westernMedicineVO);
    }

    /**
     * 西药批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("西药批量删除")
    public ResponseResult DeleteChineseMedicine(@RequestParam List<Long> ids){
        westernMedicineService.deleteWesternMedicine(ids);
        return ResponseResult.success();
    }
}
